<!-- BEGIN PAGE HEADER-->
<?php $this->load->view('partials/breadcrumb.tpl')?>
<!-- END PAGE HEADER-->
<!-- BEGIN PAGE CONTENT-->
<script type="text/javascript">
function defConfirm(url){
	if(!confirm("确定要删除吗？")){
		return false;
	}
	window.location.href = url;
	return true;
}

//修改备注信息
function setRemark(email_id,message){
	$.post('<?=site_url($thisModule.$thisController.'/ajaxAddRemark')?>',{'emailId':email_id,'remark':message},function(res){
		var retObj = JSON.parse(res);
		if(retObj.code == 1){
			
		}else{
			alert(retObj.message);
		}
	});
}

$(document).ready(function(){
	$("#reset").click(function(){
		$("select").val('');
		$("input[type='text']").val('');
	});

	$('#selectAllButton').click(function(){
		if($(this).attr('checked')){
			$("input:checkbox").parent().attr("class","checked");
		}else{
			$("input:checkbox").parent().attr("class","");
		}
	});
	$('#submitButton').click(function(){
		if($("input:checkbox").parent('span.checked').length == 0){
			alert('请至少选择一个邮箱进行操作！');
			return;
		}
		var chk_value = [];
		$("input:checkbox").parent('span.checked').each(function(){
			var chbox = $(this).children()[0];
			chk_value.push($(chbox).val());
		});
		$('#formEmailIds').val(chk_value);
		$('#emailPlusForm').submit();
			
	});
});

function checkExcelUploadForm(){
	var fileName = $("input[name='excel_file']").val();
	if(!$("input[name='excel_file']").val()){
		alert('请先选择exel文件');
		return false;
	}

	if(fileName.indexOf('email') == -1){
		alert('邮箱的excel导入文件必需以“email”开头命名！');
		return false;
	}
	
	return true;
}

function useEmail(obj,id){
	if($(obj).hasClass('red')){
		alert('您本次已经使用过该邮箱地址');
		return false;
	}
	var email_text = $(obj).parent().siblings("td.email_text").html();
	
	var oInput = document.createElement('input');
    oInput.value = email_text;
    document.body.appendChild(oInput);
    oInput.select(); // 选择对象
    document.execCommand("Copy"); // 执行浏览器复制命令
    document.body.removeChild(oInput);

	
	$.post('<?=site_url($thisModule.$thisController.'/ajaxPlusUseEmailNum')?>',{emailId:id},function(res){
		var retObj = JSON.parse(res);
		if(retObj.code == 1){
			$(obj).removeClass("green");
			$(obj).addClass("red");
			var numObj = $(obj).siblings("span.number");
			var num = parseInt($(numObj).html());
			num++;
			$(numObj).html(num.toString());
			$(obj).parent().siblings("td.use_time").html(retObj.use_current_time);
			
		}else{
			alert(retObj.message);
		}
	});
}
</script>
<div class="row">
	<div class="col-xs-12">
		<!-- Begin: life time stats -->
		<div class="portlet">
        	<form action="<?=site_url($thisModule.$thisController.'/postPlusUseEmailNum')?>" method="post" id="emailPlusForm">
            	<input type="hidden" name="ids" id="formEmailIds"/>
            </form>
			<?=form_open('', Array('class'=>'form-inline', 'role'=>'form'))?>
				<?=search_form_input('remark',filterValue('remark'),'备注搜索', 'class="form-control input-xs"');?>
				<?=search_form_input('email',filterValue('email'),'邮箱地址', 'class="form-control input-xs"');?>
				<?=search_form_input('asin',filterValue('asin'),'关联的ASIN', 'class="form-control input-xs"');?>
				<?php if($currentRoleId != 3):?>
					<?=search_form_dropdown('creator_id',array(''=>'选择创建者...')+$allReviewAdmins,filterValue('creator_id'),'创建者', 'class="form-control input-xs"');?>
				<?php endif;?>
				<?=search_form_dropdown('country',array(''=>'选择国家...')+IOSS_StaticConfig::getCountryInfo(),filterValue('country'),'国家', 'class="form-control input-xs"');?>
				<?=search_form_dropdown('status',array(''=>'选择状态...')+MEmail::getState(),filterValue('status'),'状态', 'class="form-control input-xs"');?>
				<div style="clear:both;height:15px;"></div>
                
				<div class="input-group input-xs">
                	<input type="text" class="form-control" name="email_number_perpage" value="<?=filterValue('email_number_perpage')?>" placeholder="每页显示条数">
                </div>
                <?=search_form_dropdown('email_order_type',array(''=>'排序方式...')+MEmail::getOrderType(),filterValue('email_order_type'),'排序', 'class="form-control input-xs"');?>
				<div class="input-group input-large date-picker input-daterange" data-date="" data-date-format="yyyy-mm-dd">
                	<input type="text" class="form-control" name="email_create_time_begin" value="<?=filterValue('email_create_time_begin')?>" placeholder="开始时间" autoComplete="off">
                    <span class="input-group-addon">to </span>
                    <input type="text" class="form-control" name="email_create_time_end" value="<?=filterValue('email_create_time_end')?>" placeholder="结束时间" autoComplete="off">
                </div>
                
				<button type="button" class="btn default" id="reset">重置条件</button>
				<button type="submit" class="btn green about_search">搜索 <i class="fa fa-search"></i></button>
			<?=form_close()?>
			<?=form_open_multipart(site_url($thisModule.$thisController.'/excelImportHandler'), Array('class'=>'form-inline', 'onSubmit'=>'return checkExcelUploadForm()','style'=>'margin-top:10px;text-align:right;'))?>
				<div class="form-group" style="margin-right: 30px;">
				<span>筛选后数量：<b style="color:#e20000;"><?=$filterCount;?></b> , 全部数量：<b style="color:#00a200;"><?=$totalCount?></b></span>
				</div>
				<div class="form-group">
					<label class="sr-only">商品ASIN</label>
					<input type="file" name="excel_file" class="form-control input-xs">
				</div>
				<button type="submit" class="btn red">导入Excel <i class="fa"></i></button>
			<?php form_close()?>
			<div class="portlet-body">
				<div class="row">
					<div class="col-xs-12">
						<div class="table-scrollable">
							<table class="table table-hover table-bordered table-striped">
								<thead>
    								<tr>
    									<td colspan="15" align="center">
    										<label for="selectAllButton">全选</label><input type="checkbox" id="selectAllButton"/>&nbsp;&nbsp;&nbsp;
        									<input type="button" value="每个选中的使用一次" id="submitButton"/>
    									</td>
    								</tr>
									<tr>
										<th>ID</th>
										<th>创建者</th>
										<th>关联ASIN</th>
										<th>联系人姓名</th>
										<th>联系人资料</th>
										<th>国家</th>
										<th>投票</th>
										<th>排名</th>
										<th>email</th>
										<th>发邮件次数</th>
										<th>上次发邮件时间</th>
										<th>状态</th>
										<th width="10%">备注</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>
								<?php foreach($list as $v){?>
									<tr>
										<td><?=$v->id?></td>
										<td><?=$allReviewAdmins[$v->creator_id];?></td>
										<td><?=$v->asin;?></td>
										<td><?=htmlspecialchars($v->name)?></td>
										<td>
										<?php if($v->profile):?>
										<a href="<?=$v->profile?>" target="_blank">打开</a>
										<?php else:?>
										没有
										<?php endif;?>
										</td>
										<td><?=IOSS_StaticConfig::getCountryInfo(strtoupper($v->country))?></td>
										<td><?=$v->votes?></td>
										<td><?=$v->ranking?></td>
										<td class="email_text"><?=$v->email?></td>
										<td>
											<span class="number"><?=$v->email_times?></span> | <a class="btn btn-xs green" onclick="useEmail(this,<?=$v->id?>);">使用一次</a>
											<input type="checkbox" name="id[]" value="<?=$v->id?>"/>
										</td>
										<td class="use_time"><?=$v->email_last_time>0?date('Y-m-d H:i:s',$v->email_last_time):'未使用过'?></td>
										<td><?=MEmail::getState($v->status)?></td>
										<td><textarea onBlur="setRemark(<?=$v->id?>,this.value)"><?=$v->remark;?></textarea></td>
										<td>
											<a href="javascript:ioss_url_modal('<?=site_url($thisModule.$thisController.'/ajaxViewDetail/'.$v->id)?>');" class="about_edit btn <?=$p->read?'':'disabled' ?>" ><i class="fa fa-play"></i> 查看</a>
											<a href="<?=site_url($thisModule.$thisController.'/edit/'.$v->id)?>" class="about_edit btn <?=$p->edit?'':'disabled' ?>" ><i class="fa fa-edit"></i> 编辑</a>
											<?php if($p->delete){?>
											<a class="black" href="javascript:void(defConfirm('<?=site_url($thisModule.$thisController.'/delete/'.$v->id.'/'.$v->update_time) ?>'));"><i class="fa fa-trash-o"></i> <?=l('delete')?></a>
											<?php }?>
										</td>
									</tr>
								<?php }?>
								
								</tbody>
							</table>
						</div>
					</div>
				</div>
				<div class="row">
					<div class="col-xs-12 text-right">
						<?=$pagination?>
					</div>
				</div>
			</div>
		</div>
		<!-- End: life time stats -->
	</div>
</div>
<!-- END PAGE CONTENT-->
